version 16
set more off
program drop _all
log using finalanalysisPartI.log, text replace


/*	*********************************************************************************/
/*     	File Name:	Studying Nonobviousness Part I									*/
/*     	Date:   	February 25, 2021												*/
/*      Author: 	Abigail Matthews and Jason Rantanen								*/
/*      Purpose:	Code for Part I of Studying Nonobviousness			 			*/
/* 		Input files: "Holte and Sichelman 2020.dta"									*/
/*					 "Rantanen 2013.dta"											*/
/*					"Multi-analysis coding.dta"										*/
/*					"Rantanen to Holte Sichelman matched cases.dta"					*/
/*					"2020-06-16LK Coding of unmatched records.dta"					*/
/*      Output File: "Part I dataset for analysis.dta"								*/
/*	*********************************************************************************/


ssc install kappaetc /* To make run IRR commands, install program */
ssc install asdoc 	 /* To make tables that export to Word */
ssc install estout   /* To make tables from probit analyses */ 


****************************************
/* Prepping Holte & Sichelman Dataset */
****************************************

/* In order to compare the data from Rantanen to Holte & Sichelman, it was necessary
to put the two datasets in a similar format.  This section prepares the data received 
from Holte & Sichelman for the comparison. */

use "Holte and Sichelman 2020.dta", clear

//Drop variables that won't be used in the analysis
drop Technology-P
drop necessary
drop Obviousness_Necessary
drop Analysis_4-Analysis_17
drop Problem_to_be_solved-Hindsight_Bias
drop Prior_Art_1-Full_Cite_1
drop Plaintiff-Prior_History
drop Counsel-Precedential
drop EnBanc-OtherJudges_Opinion1
drop KSR_Cite-WinnerinDistrictCt
drop CAFCCaseDecision-DctDecisionToCode
drop CaseCounted
drop DispositionInferred
drop Disposition
drop Serial
drop NotesoncodingDctDecision


/*Create a single variable that indicates procedural posture that is generated from
the binary variables.*/

gen ProceduralPosture = 1 if jury ==1
replace ProceduralPosture = 2 if bench==1
replace ProceduralPosture = 3 if jmol==1
replace ProceduralPosture = 4 if sj==1
replace ProceduralPosture = 5 if prelim==1
replace ProceduralPosture = 6 if other==1
replace ProceduralPosture = 7 if ((jury + bench + jmol + sj + prelim + other) > 1)
recode ProceduralPosture (6=7) (7=6)
label define ProceduralPosture 1 Jury 2 Bench 3 JMOL 4 SJ 5 PI 6 "Multiple Postures" 7 Other, replace
label values ProceduralPosture ProceduralPosture
tab ProceduralPosture

/*Prepare the Posture Outcome data for analysis*/
replace DistrictCourtMerge="Nonobvious" if DistrictCourtMerge=="Nonbvious"

tab DistrictCourtMerge 
sort DistrictCourtMerge
encode DistrictCourtMerge, gen(Posture_Outcome)
drop DistrictCourtMerge
rename Posture_Outcome DistrictCourtMerge
tab DistrictCourtMerge
recode DistrictCourtMerge (1=3) (3=1)
label define PostureOutcome 1 Obvious 2 Nonobvious 3 "Both", replace
label values DistrictCourtMerge PostureOutcome
tab DistrictCourtMerge

/*Prepare the CAFC Outcome data for analysis*/

replace Block_Result="Nonobvious" if Block_Result=="nonobvious"
replace Block_Result="Obvious" if Block_Result=="obvious"
tab Block_Result
sort Block_Result
encode Block_Result, gen(Block_Result_temp)
drop Block_Result
rename Block_Result_temp Block_Result
tab Block_Result
recode Block_Result (3=1) (1=3)
label define Block_Result 1 Obvious 2 Nonobvious 3 "Mixed Outcomes" 4 "No Final Determination", replace
label values Block_Result Block_Result
tab Block_Result

/*Prepare the disposition data for analysis*/
replace DispositionCondensed = "Affirmed" if DispositionCondensed == "Affirmed "
replace DispositionCondensed = "Reversed" if DispositionCondensed == "Reversed "
replace DispositionCondensed = "Affirmed" if DispositionCondensed == "affirmed "
replace DispositionCondensed = "Affirmed" if DispositionCondensed == "affirmed"
replace DispositionCondensed = "Reversed" if DispositionCondensed == "reversed"
tab DispositionCondensed

tab DispositionCondensed, mi
sort DispositionCondensed
encode DispositionCondensed, gen (DispositionCondensed_temp)
drop DispositionCondensed
rename DispositionCondensed_temp DispositionCondensed
recode DispositionCondensed (4=2) (2=4) (3=5) (5=3)
recode DispositionCondensed (3=4) (4=3)
label define DispositionCondensed 1 Affirmed 2 Reversed 3 Vacated 4 "Mixed Dispositions" 5 "No Final Determination", replace
label values DispositionCondensed DispositionCondensed
tab DispositionCondensed

//Prepare the TSM_Use data for analysis

tab TSM_Use
sort TSM_Use
encode TSM_Use, gen(TSM_Use_temp)
drop TSM_Use
rename TSM_Use_temp TSM_Use
tab TSM_Use
recode TSM_Use (1=2) (3=1) (.=2)
label define TSM_Use 1 Yes 2 No
label values TSM_Use TSM_Use
tab TSM_Use

//Prepare the TSM_Formal data for analysis

tab TSM_Formal
sort TSM_Formal
encode TSM_Formal, gen(TSM_Formal_temp)
drop TSM_Formal
rename TSM_Formal_temp TSM_Formal
tab TSM_Formal
recode TSM_Formal (3=1) (1=2) (4=2) (.=2)
label define TSM_Formal 1 Yes 2 No
label values TSM_Formal TSM_Formal
tab TSM_Formal

//Prepare the Common_Sense_Used data for analysis

tab Common_Sense_Used
sort Common_Sense_Used
encode Common_Sense_Used, gen(Common_Sense_Used_temp)
drop Common_Sense_Used
rename Common_Sense_Used_temp Common_Sense_Used
tab Common_Sense_Used
recode Common_Sense_Used (2=1) (3=1) (.=2) (1=2)
label define Common_Sense_Used 1 Yes 2 No
label values Common_Sense_Used Common_Sense_Used
tab Common_Sense_Used

//Clean the Rule 36 data

replace Rule_36 = "No" if Rule_36=="NO" | Rule_36=="No " | Rule_36=="no"
replace Rule_36 = "Yes" if Rule_36=="YES" | Rule_36=="Yes, R36" | Rule_36=="yes"
replace Rule_36="No" if number==12 //This was coded strangely in the data from H&S

//Apply a prefix to all fields in Holte & Sichelman
rename * HS_=

//Save the prepped file
save "Holte and Sichelman 2020 - prepped.dta", replace


***************************
/* Prepping Rantanen 2013 Dataset */
***************************

use "Rantanen 2013.dta", clear

/*This comparison uses the opinion as the unit of analysis.  Consequently, only
one record per case should be kept.*/
  
drop if AnalysisN=="A02" | AnalysisN=="A03" | AnalysisN=="A04"

//This left a few duplicates for which AnalysisN was not coded correctly  

duplicates report Case_serial
duplicates drop Case_serial, force

/*In addition, it was necessary to account for opinions with multiple 
distinct obviousness analyses with inconsistent coding within the opinion. These
were individually coded by identifying opinions with muliple analyses and determining
whether those intra-opinion analyses were different with respect to a given field.

The analysis sheet is entitled "2020-08-35 Multi-Analyses for CAFC_Patent_Obviousness_Used_2014-09-08"   

The file 2020-11-20 Multi-analysis coding.dta contains the records with multiple
different analyses.*/

merge m:1 Case_serial using "Multi-analysis coding.dta", update replace 
drop _merge

//Drop unused fields
drop Serial
drop Docket
drop Obviousness_Initial
drop Opinion1_Type-Opinion3_Type
drop AnalysisN-Patent5
drop Disposition
drop Predictable_Uses
drop Obviousness_Necessary
drop KSR_Cite
drop Notes
drop PostKSR
drop Obviousness_Final

//Rename the variables with an R prefix
rename * R_=

//Prepare the procedural posture coding for analysis
sort R_ProceduralPosture
encode R_ProceduralPosture, gen(ProceduralPosture)
drop R_ProceduralPosture
rename ProceduralPosture R_ProceduralPosture
tab R_ProceduralPosture
recode R_ProceduralPosture (2=1) (3=2) (4=3) (5=4) (6=5) (7=8) (8=7) (9=6) (1=9)
label define ProceduralPosture 1 Jury 2 Bench 3 JMOL 4 SJ 5 PI 6 "Multiple Postures" 7 Interference 8 ITC 9 PTO, replace
label values R_ProceduralPosture ProceduralPosture
tab R_ProceduralPosture

//Prepare the Posture Outcome data for analysis
tab R_PostureOutcome
sort R_PostureOutcome
encode R_PostureOutcome, gen(Posture_Outcome)
drop R_PostureOutcome
rename Posture_Outcome R_PostureOutcome
tab R_PostureOutcome, nolabel
recode R_PostureOutcome (2=1) (1=2) 
label define PostureOutcome 1 Obvious 2 Nonobvious 3 Both, replace
label values R_PostureOutcome PostureOutcome
tab R_PostureOutcome
label variable R_ProceduralPosture "Rantanen Procedural Posture"

//Prepare the CAFC Result data for analysis
tab R_CAFC_Result
sort R_CAFC_Result
encode R_CAFC_Result, gen(CAFC_Result)
drop R_CAFC_Result
rename CAFC_Result R_CAFC_Result
tab R_CAFC_Result
recode R_CAFC_Result (3=4) (4=3) (1=2) (2=1)
label define CAFC_Result 1 Obvious 2 Nonobvious 3 "Mixed Outcomes" 4 "No Final Determination", replace
label values R_CAFC_Result CAFC_Result
tab R_CAFC_Result

//Prepare the disposition data for analysis
tab R_DispositionCondensed, missing 
sort R_DispositionCondensed
encode R_DispositionCondensed, gen(DispositionCondensed)
drop R_DispositionCondensed
rename DispositionCondensed R_DispositionCondensed
recode R_DispositionCondensed (1=2) (2=1) (4=1) (5=4)
label define DispositionCondensed 1 Affirmed 2 Reversed 3 Vacated 4 "Mixed Dispositions", replace
label values R_DispositionCondensed DispositionCondensed
tab R_DispositionCondensed

//Prepare the TSM_Use data
tab R_TSM_Use, missing
tab R_TSM_Use
recode R_TSM_Use (0=1) (.=1) (1=2)
label define  R_TSM_Use 1 No 2 Yes
label values  R_TSM_Use R_TSM_Use
tab R_TSM_Use

//Prepare the TSM_Formal data
tab R_TSM_Formal, missing
tab R_TSM_Formal
recode R_TSM_Formal (0=1) (.=1) (1=2)
label define  R_TSM_Formal 1 No 2 Yes
label values  R_TSM_Formal R_TSM_Formal
tab R_TSM_Formal

//Prepare the Common_Sense_Used data
tab R_CommonSenseUsed, missing
sort R_CommonSenseUsed
recode R_CommonSenseUsed (0=1) (.=1) (1=2)
label define R_CommonSenseUsed 1 No 2 Yes
label values R_CommonSenseUsed R_CommonSenseUsed
tab R_CommonSenseUsed

//Save the prepped dataset
save "Rantanen 2013 - prepped.dta", replace

***************************
/* Matching the records in both datasets */
***************************

//Open the key file and correct the HS_number field name
use "Rantanen to Holte Sichelman matched cases.dta"

rename SNumber HS_number
rename Case_serial R_Case_serial

//temporarily alter the HS_Number in the key file to avoid issues.
replace HS_number = 1000 if HS_number==.

//Next, merge the two datasets into the key file
merge m:m HS_number using "Holte and Sichelman 2020 - prepped.dta"

//restore the HS_number to a blank
replace HS_number = . if HS_number==1000

//repeat with the Rantanen 2020 dataset
replace R_Case_serial="blank" if R_Case_serial==""
drop _merge
merge m:m R_Case_serial using "Rantanen 2013 - prepped.dta"
replace R_Case_serial = "" if R_Case_serial=="blank"

/*two records from the using dataset were not matched.  One of these is an appeal 
from the USPTO and will be dropped; the other was a case that was 
erroneously included twice, the first time with an incorrect citation. */

replace R_Full_Cite = "55 Fed.Appx. 918" if R_Case_serial=="C00372"
drop if R_Case_serial=="C00373"

//Drop the _merge field
drop _merge

/*Finally, we need to drop the cases that will not be part of the analysis: the 
appeals from the USPTO and ITC from Rantanen 2013*/
tab R_ProceduralPosture
drop if R_ProceduralPosture == 7 | R_ProceduralPosture == 8 | R_ProceduralPosture == 9 

/*We also need to drop the two Court of Federal Claims decisions that H&S 
included in their initial case count and dataset.  The complete dataset that H&S 
subsequently provided did not have these two decisions.*/ 
drop if HS_number==75 | HS_number==152

***********************************
/*Creating the comparison variables*/
***********************************

/*The next step in the analysis is creating the comparison variables.  These 
will be what we use to do the comparison analysis. First we'll generate a single field date variable*/

tab HS_Date R_Date if HS_Date!=R_Date & HS_Date!=. & R_Date!=.

/*This report indicates that there are only 3 instances in which the HS_Date does 
not match the R_Date (provided that both are present).  None of those discrepencies 
matter for purposes of the analysis so we will just use R_Date*/

gen Date=R_Date
replace Date=HS_Date if Date==.

/* Generate a universal Rule 36 variable.  There are two instances in which 
the H&S coding on Rule 36 does not match the R coding, HS_number 24 and 133.  
Rantanen reviewed these and both were erroneously coded as Rule 36 by H&S. Rantanen 
2013 coding will thus overide H&S on these. */

gen Rule_36 = R_Rule_36
replace Rule_36 = 0 if HS_Rule_36=="No" & Rule_36==.
replace Rule_36 = 1 if HS_Rule_36=="Yes" & Rule_36==.
replace Rule_36 = 0 if UniqueID=="10942"

//Generate the pre/post KSR variable that includes the post-cert/pre-decision period
gen PostKSR = 2 if (Date >= date("6/26/2006", "MDY") & Date <=date("04/30/2007", "MDY"))
replace PostKSR = 3 if (Date > date("04/30/2007", "MDY"))
replace PostKSR = 1 if (Date < date("6/26/2006", "MDY"))
label define PostKSR 1 "Pre cert" 2 "Between cert and decision" 3 "After decision", replace
label values PostKSR PostKSR
tab PostKSR

//Generate the pre/post KSR variable that is based only on decision date
gen PostKSR_decision = 1 if PostKSR == 3
replace PostKSR_decision = 0 if PostKSR_decision==.
label define PostKSR_decision 0 "Pre decision" 1 "Post decision", replace
label values PostKSR_decision PostKSR_decision
tab PostKSR_decision

//Generate the time-based indicator variable to indicate whether a given decision is within the overlapping time period.
gen Time_Range = 1 if (Date >= date("1/1/2003", "MDY") & Date <=date("04/30/2012", "MDY"))
replace Time_Range=0 if Time_Range==.

//Generate indicator variable to tell us if a decision is in one dataset or the other. 
gen HS_Dataset = 1 if HS_number!=.
replace HS_Dataset= 0 if HS_Dataset==.

gen R_Dataset = 1 if R_Case_serial!=""
replace R_Dataset = 0 if R_Dataset==.

tab HS_Dataset R_Dataset if Time_Range==1

/*Generate an indicator variable for the Time and Type comparison*/
gen Time_Type_Set=1 if Time_Range==1
replace Time_Type_Set=0 if Time_Type_Set==.
tab HS_ProceduralPosture R_ProceduralPosture if Time_Type_Set==1, missing
tab HS_ProceduralPosture R_ProceduralPosture if R_Dataset==1 & HS_Dataset==1 & Time_Type_Set==1, missing

/* There were a small number of decisions that were present in both datasets but which did not meet the criteria. While we initially included a decision as long as it met the criteria in one of the datasets, after receiving comments we decided to only include a decision in a dataset if it met the inclusion criteria as applied to just that dataset.  This resulted in the removal of four decisions from the Rantanen dataset that were also present in Holte & Sichelman (2019) and three decisions from Holte & Sichelman that were also present in Rantanen (2013).  Specifically, three of the decisions in Rantanen (2013) were coded as “2-No Final Decision” but had final determinations in Holte & Sichelman (2019).  We did not include those decisions in the Rantanen (2013) dataset (but kept them in Holte & Sichelman (2019)). We also did not keep one decision coded as “vacate” in Holte & Sichelman (2019) for the same reason. Similarly, one decision was coded in Holte & Sichelman as arising from a preliminary injunction and two were coded with a procedural posture of “other,” but were coded as arising from Jury, JMOL or Summary Judgment in Rantanen (2013).  These decisions were not kept in Holte & Sichelman but were kept in Rantanen.  Finally, there was one decision in Rantanen (2013) that did not have the procedural posture coded but was coded as arising in the context of Summary Judgment in Holte & Sichelman (2019).  We did not keep this decision in the Rantanen dataset.   (There were no remaining decisions in Rantanen (2013) that were coded as vacates). */ 
 
/*There is one record that both datasets code as a PI, one record that is only in H&S
that is coded as a PI, and 16 records that are only in Rantanen that are coded as PI.
All of these are not part of the analysis. */

replace HS_Dataset = 0 if HS_ProceduralPosture==5
replace R_Dataset= 0 if R_ProceduralPosture==5

/* There are two records that H&S coded as "other" These will not be included in
the HS_Dataset for comparison */

replace HS_Dataset = 0 if HS_ProceduralPosture==7

/* There is one record that Rantanen did not have a procedural posture for.  This
record was not kept in the R_Dataset*/

replace R_Dataset= 0 if R_ProceduralPosture==.

/* Because H&S limited their analysis to final determinations, records appearing only
in Rantanen that were coded as "No Final Determination" will not be included in
the Rantanen Dataset, a decision made on 2021-02-05.*/

tab HS_Block_Result R_CAFC_Result if Time_Type_Set==1, missing
tab R_CAFC_Result R_Dataset, missing
replace R_Dataset=0 if R_CAFC_Result==4

/* For the same reason, decisions with a disposition of "Vacate" were not included
in the HS_dataset used for analysis.*/

tab HS_Disposition R_Disposition if Time_Type_Set==1, missing
replace HS_Dataset=0 if HS_Disposition==3

//Generate an indicator for decisions that are in both datasets

gen Comparison_Set=1 if HS_Dataset == 1 & R_Dataset==1

//There is one duplicate to drop.

duplicates report
duplicates drop

//Account for records in the Time_Type_Set field that did not meet the criteria for either datasets

replace Time_Type_Set = 0 if R_Dataset==0 & HS_Dataset==0

/* Merging LK's coding of the records that appeared in only one dataset */

merge m:m HS_number using "2020-06-16LK Coding of unmatched records.dta", keepusing(LK_Section_103_Issue ComparisonNotes_Kriz)
drop if _merge==2
drop _merge
merge m:m R_Case_serial using "2020-06-16LK Coding of unmatched records.dta", keepusing(LK_Section_103_Issue ComparisonNotes_Kriz) update
drop _merge

save "Part I dataset for analysis", replace
erase "Holte and Sichelman 2020 - prepped.dta"
erase "Rantanen 2013 - prepped.dta"


*********************************************************
/*		Construction of tables in Part I 	*/
*********************************************************

use "Part I dataset for analysis.dta", clear

***************************
/* PART I.A.: Comparison of Results*/
***************************

/*The first part of the analysis compares the results reported by the two datasets.  It
uses the parameter Time_Type_Set, which denotes records within the period during
which both studies overlap (January 1, 2003 - April 30, 2012).  It also uses the HS_Dataset
and R_Dataset parameters, which indicate records that are present in one of the two 
datasets.*/

**# TABLE 1 RECORDS IN DATASETS **
tab HS_Dataset R_Dataset if Time_Type_Set==1, missing
tab PostKSR R_Dataset if Time_Type_Set ==1, missing
tab PostKSR HS_Dataset if Time_Type_Set ==1, missing


**# TABLE  2: PROCEDURAL POSTURE OF DISTRICT COURT DETERMINATIONS REVIEWED BY FEDERAL CIRCUIT **
tab R_ProceduralPosture PostKSR_decision if R_Dataset == 1 & Time_Type_Set==1, missing
tab HS_ProceduralPosture PostKSR_decision if HS_Dataset==1 & Time_Type_Set==1, missing

tab R_ProceduralPosture if R_Dataset==1& Time_Type_Set==1, missing
tab HS_ProceduralPosture if HS_Dataset==1 & Time_Type_Set==1, missing

tab R_ProceduralPosture if R_Dataset==1 & Time_Type_Set==1 & (R_ProceduralPosture==1 | R_ProceduralPosture==2 | R_ProceduralPosture==3 | R_ProceduralPosture==4)
tab HS_ProceduralPosture if HS_Dataset==1 & Time_Type_Set==1 & (HS_ProceduralPosture == 1 | HS_ProceduralPosture == 2 | HS_ProceduralPosture == 3 | HS_ProceduralPosture == 4)


**# TABLE 3: DISTRICT COURT DETERMINATIONS REVIEWED BY THE FEDERAL CIRCUIT **
tab R_PostureOutcome PostKSR_decision if R_Dataset ==1 & Time_Type_Set==1, missing
tab HS_DistrictCourtMerge PostKSR_decision if HS_Dataset==1 & Time_Type_Set==1, missing

tab R_PostureOutcome PostKSR_decision if R_Dataset ==1 & Time_Type_Set==1 & (R_PostureOutcome==1 | R_PostureOutcome==2)
tab HS_DistrictCourtMerge PostKSR_decision if HS_Dataset==1 & Time_Type_Set==1 & (HS_DistrictCourtMerge==1 | HS_DistrictCourtMerge==2)


**# TABLE 4: FEDERAL CIRCUIT DETERMINATIONS OF "OBVIOUS" **
tab R_CAFC_Result PostKSR_decision if R_Dataset==1 & Time_Type_Set==1, missing
tab HS_Block_Result PostKSR_decision if HS_Dataset==1 & Time_Type_Set==1, missing

tab R_CAFC_Result PostKSR_decision if R_Dataset==1 & Time_Type_Set==1 & (R_CAFC_Result==1 | R_CAFC_Result==2)
tab HS_Block_Result PostKSR_decision if HS_Dataset==1 & Time_Type_Set==1 & (HS_Block_Result==1 | HS_Block_Result==2)

tab R_CAFC_Result PostKSR if R_Dataset==1 & Time_Type_Set==1
tab HS_Block_Result PostKSR if HS_Dataset==1 & Time_Type_Set==1


**# TABLE 5: FEDERAL CIRCUIT DISPOSITIONS WHEN MAKING FINAL DETERMINATIONS ON OBVIOUSNESS **
tab R_DispositionCondensed PostKSR_decision if R_Dataset==1 & Time_Type_Set == 1, missing
tab HS_DispositionCondensed PostKSR_decision if HS_Dataset==1 & Time_Type_Set == 1, missing

tab R_DispositionCondensed PostKSR_decision if R_Dataset==1 & Time_Type_Set == 1 & (R_DispositionCondensed==1 | R_DispositionCondensed==2)
tab HS_DispositionCondensed PostKSR_decision if HS_Dataset==1 & Time_Type_Set == 1 & (HS_DispositionCondensed ==1 | HS_DispositionCondensed ==2)


**# TABLE 6: COMPARISON OF DECISIONS INCLUDED IN EACH DATASET
tab HS_Dataset R_Dataset if Time_Type_Set==1, missing
tab PostKSR_decision if HS_Dataset==1 & R_Dataset!=1 & Time_Type_Set==1, missing
tab PostKSR_decision if HS_Dataset!=1 & R_Dataset==1 & Time_Type_Set==1, missing

//Shows the number in both datasets relative to KSR
tab PostKSR_decision if Comparison_Set==1 & Time_Type_Set==1 
tab PostKSR_decision if Time_Type_Set==1





use "Part I dataset for analysis.dta", clear


/* This keeps only records that are in both data sets and in the same time period*/
keep if Time_Type_Set==1


***************************
/* Cases in Both Datasets */
***************************

tab HS_Dataset R_Dataset
label define Data 1 Yes 0 No, replace
label values HS_Dataset Data
label values R_Dataset Data 
tab HS_Dataset R_Dataset

label variable HS_Dataset"Case Included in Holte & Sichelman"
label variable R_Dataset "Case Included in Rantanen"

//Records only in Rantanen dataset
tab PostKSR_decision if HS_Dataset==0 & R_Dataset==1

//Records only in H&S dataset
tab PostKSR_decision if HS_Dataset==1 & R_Dataset==0

//Records in both datasets
tab PostKSR_decision if HS_Dataset==1 & R_Dataset==1

asdoc tab HS_Dataset R_Dataset, label font(Times New Roman) fs(12) save(dataset.doc) replace title(\i) 


kappaetc HS_Dataset R_Dataset
kap HS_Dataset R_Dataset /* for expected agreement */


sort Date
gen caseID = _n
expand 2
gen rater = 1 /* Rater 1 is Holte & Sichelman. */
sort caseID

/* This makes every other observation into rater 2 (Rantanen). */
forvalues i = 1/416 {
   bys caseID: replace rater=2 if rater[_n]==1 & rater[_n-`i']==1
}

/* This creates a variable for whether each rater included the case in the dataset. */
gen rating = 0
replace rating =1 if rater==1 & HS_Dataset==1
replace rating =1 if rater==2 & R_Dataset==1


/* This calculates the intraclass correlation for the agreement. */
icc rating caseID rater, mixed


		*********************************************
		/*		Cases in Only One Datasets	 		*/ 
		*********************************************

use "Part I dataset for analysis.dta", clear

keep if Time_Type_Set==1
		
/* This code compares the four key variables for those cases that meet the comparison criteria
but which are contained in only one dataset. It also reports on LK's coding of the single-
dataset cases */
		
gen Single_Dataset = 1 if R_Dataset==1 & HS_Dataset==0
replace Single_Dataset=1 if R_Dataset==0 & HS_Dataset==1

gen Dataset_id = 1 if HS_Dataset==1
replace Dataset_id = 2 if R_Dataset==1

label define data_id 1 "Holte & Sichelman only" 2 "Rantanen only"
label values Dataset_id data_id
label variable Dataset_id Dataset

sort LK_Section_103_Issue
encode(LK_Section_103_Issue), gen(temp)
drop LK_Section_103_Issue
rename temp LK_Section_103_Issue

label define LK_Section_103_Issue 1 "Definitely" 2 "Not sure" 3 "Definitely not" 4 "Rule 36"
label values LK_Section_103_Issue LK_Section_103_Issue
label variable LK_Section_103_Issue "Determination of whether decision involved 103"

gen Single_Dataset_ProcPost = HS_ProceduralPosture if Single_Dataset==1 & HS_Dataset==1
replace Single_Dataset_ProcPost = R_ProceduralPosture if Single_Dataset_ProcPost == . & Single_Dataset==1 & R_Dataset==1
label values Single_Dataset_ProcPost ProceduralPosture
label variable Single_Dataset_ProcPost "Procedural Posture"

gen Single_Dataset_PostOutcome = HS_DistrictCourtMerge if Single_Dataset==1 & HS_Dataset==1
replace Single_Dataset_PostOutcome = R_PostureOutcome if Single_Dataset_PostOutcome == . & Single_Dataset==1 & R_Dataset==1
label values Single_Dataset_PostOutcome PostureOutcome
label variable Single_Dataset_PostOutcome "Posture Outcome"

gen Single_Dataset_CAFC_Result = HS_Block_Result if Single_Dataset==1 & HS_Dataset==1
replace Single_Dataset_CAFC_Result = R_CAFC_Result if Single_Dataset_CAFC_Result == . & Single_Dataset==1 & R_Dataset==1
label values Single_Dataset_CAFC_Result Block_Result
label variable Single_Dataset_CAFC_Result "CAFC Result"

gen Single_Dataset_DispCond = HS_DispositionCondensed if Single_Dataset==1 & HS_Dataset==1
replace Single_Dataset_DispCond = R_DispositionCondensed if Single_Dataset_DispCond == . & Single_Dataset==1 & R_Dataset==1
label values Single_Dataset_DispCond DispositionCondensed
label variable Single_Dataset_DispCond "Disposition"


**# TABLE 7: ANALYSIS OF DECISIONS INCLUDED IN ONLY ONE DATASET** 
asdoc tab Dataset_id LK_Section_103_Issue if Single_Dataset==1, label font(Times New Roman) fs(12) save(singleDataset.doc) replace title(\i)

**# TABLE 8: VARIABLE COMPARISONS OF DECISIONS IN ONLY ONE DATASET** 
asdoc tab Single_Dataset_ProcPost Dataset_id if Single_Dataset==1, label font(Times New Roman) fs(10) save(singleDataset.doc) append title(\i) 
asdoc tab Single_Dataset_PostOutcome Dataset_id if Single_Dataset==1, label font(Times New Roman) fs(10) save(singleDataset.doc) append title(\i) 
asdoc tab Single_Dataset_CAFC_Result Dataset_id if Single_Dataset==1, label font(Times New Roman) fs(10) save(singleDataset.doc) append title(\i) 
asdoc tab Single_Dataset_DispCond Dataset_id if Single_Dataset==1, label font(Times New Roman) fs(10) save(singleDataset.doc) append title(\i) 



		*********************************************
		/*		Prepping for Rest of Analysis 		*/ 
		*********************************************

keep if Comparison_Set==1

**# Appendix A1 Kappa values are in the code below. 


************************
/* Procedural Posture */
************************

**# TABLE 9: COMPARISON OF PROCEDURAL POSTURES FOR DECISIONS IN BOTH DATASETS
label variable HS_ProceduralPosture "Holte & Sichelman Procedural Posture"
label variable R_ProceduralPosture "Rantanen Procedural Posture"
asdoc tab HS_ProceduralPosture R_ProceduralPosture, label font(Times New Roman) fs(12) save(Part I tables.doc) replace title(\i) 

kappaetc HS_ProceduralPosture R_ProceduralPosture
kappaetc HS_ProceduralPosture R_ProceduralPosture, benchmark showscale
kap HS_ProceduralPosture R_ProceduralPosture,tab 


*******************************
/*  Obvious: Posture_Outcome  */
*******************************
**# TABLE 10: COMPARISON OF DISTRICT COURT OUTCOMES FOR DECISIONS IN BOTH DATASETS
label variable HS_DistrictCourtMerge "Holte & Sichelman Lower Court Result"
label variable R_PostureOutcome "Rantanen Lower Court Result"
asdoc tab HS_DistrictCourtMerge R_PostureOutcome, label font(Times New Roman) fs(12) save(Part I tables.doc) append title(\i) 

kap HS_DistrictCourtMerge R_PostureOutcome, tab
kappaetc HS_DistrictCourtMerge R_PostureOutcome, benchmark showscale


***************************
/*  Obvious: CAFC Result  */
***************************
**# TABLE 11: COMPARISON OF FEDERAL CIRCUIT OUTCOMES FOR DECISIONS IN BOTH DATASETS
label variable HS_Block_Result "Holte & Sichelman Federal Circuit Result"
label variable R_CAFC_Result "Rantanen Federal Circuit Result"
asdoc tab HS_Block_Result R_CAFC_Result, label font(Times New Roman) fs(12) save(Part I tables.doc) append title(\i) 

kap HS_Block_Result R_CAFC_Result, tab
kappaetc HS_Block_Result R_CAFC_Result
kappaetc HS_Block_Result R_CAFC_Result, benchmark showscale


****************************
/*  Appellate Disposition  */
****************************
**# TABLE 12: COMPARISON OF APPELLATE DISPOSITIONS FOR DECISIONS IN BOTH DATASETS
label variable HS_DispositionCondensed"Holte & Sichelman Federal Circuit Disposition"
label variable R_DispositionCondensed "Rantanen Federal Circuit Disposition"
tab HS_DispositionCondensed R_DispositionCondensed
asdoc tab HS_DispositionCondensed R_DispositionCondensed, label font(Times New Roman) fs(12) save(Part I tables.doc) append title(\i) 

kap HS_DispositionCondensed R_DispositionCondensed, tab
kappaetc HS_DispositionCondensed R_DispositionCondensed 
kappaetc HS_DispositionCondensed R_DispositionCondensed, benchmark showscale



**# TABLE 13a: COMPARISON OF ANALYSIS CODING FOR DECISIONS CONTAINED IN BOTH DATASETS
**************************
/* TSM Common Sense Used */
**************************

tab HS_Common_Sense_Used 

tab R_CommonSenseUsed
recode R_CommonSenseUsed (1=2) (2=1)
label define CommonSense 1 Yes 2 No, replace
label values R_CommonSenseUsed CommonSense
tab R_CommonSenseUsed

label variable HS_Common_Sense_Used "Holte & Sichelman Court Used Common Sense"
label variable R_CommonSenseUsed "Rantanen Court Used Common Sense"

tab HS_Common_Sense_Used R_CommonSenseUsed if Rule_36==0

asdoc tab HS_Common_Sense_Used R_CommonSenseUsed if Rule_36==0, label font(Times New Roman) fs(12) save(Part I tables.doc) append title(\i) 

kap HS_Common_Sense_Used R_CommonSenseUsed if Rule_36==0, tab
kappaetc HS_Common_Sense_Used R_CommonSenseUsed if Rule_36==0
kappaetc HS_Common_Sense_Used R_CommonSenseUsed if Rule_36==0, benchmark showscale

**# TABLE 13b: COMPARISON OF ANALYSIS CODING FOR DECISIONS CONTAINED IN BOTH DATASETS
************************
/*    TSM_Formal    */
************************

tab HS_TSM_Formal

tab R_TSM_Formal
recode R_TSM_Formal (2=1) (1=2)
label define TSM_Formal 1 Yes 2 No, replace
label values R_TSM_Formal TSM_Formal
tab R_TSM_Formal

label variable HS_TSM_Formal "Holte & Sichelman TSM Formal"
label variable R_TSM_Formal "Rantanen TSM Formal"

tab HS_TSM_Formal R_TSM_Formal if Rule_36==0, missing
asdoc tab HS_TSM_Formal R_TSM_Formal if Rule_36==0, label font(Times New Roman) fs(12) save(Part I tables.doc) append title(\i) 

kap HS_TSM_Formal R_TSM_Formal if Rule_36==0, tab
kappaetc HS_TSM_Formal R_TSM_Formal if Rule_36==0
kappaetc HS_TSM_Formal R_TSM_Formal if Rule_36==0, benchmark showscale

**# TABLE 13c: COMPARISON OF ANALYSIS CODING FOR DECISIONS CONTAINED IN BOTH DATASETS
************************
/*     TSM_Use  	  */
************************

*gsort -HS_TSM_Use
*encode HS_TSM_Use, gen(TSM_Use)
*drop HS_TSM_Use
*rename TSM_Use HS_TSM_Use

tab HS_TSM_Use

tab R_TSM_Use
recode R_TSM_Use (1=2) (2=1)
label define TSM_Use 1 Yes 2 No, replace
label values R_TSM_Use TSM_Use
tab R_TSM_Use

label variable HS_TSM_Use "Holte & Sichelman Some Use of TSM"
label variable R_TSM_Use "Rantanen Some Use of TSM"

**# 
tab HS_TSM_Use R_TSM_Use if Rule_36==0, missing
asdoc tab HS_TSM_Use R_TSM_Use if Rule_36==0, label font(Times New Roman) fs(12) save(Part I tables.doc) append title(\i) 

kap HS_TSM_Use R_TSM_Use if Rule_36==0, tab
kappaetc HS_TSM_Use R_TSM_Use if Rule_36==0
kappaetc HS_TSM_Use R_TSM_Use if Rule_36==0, benchmark showscale

 
***********************************
/* 	Appendix C Probit Models	 */
***********************************

use "Part I dataset for analysis.dta", clear

*keep if Time_Type_Set==1 // Let's drop this restriction.

gen R_postKSRcert=1 if PostKSR==3
replace R_postKSRcert=1 if PostKSR==2 // Added to include cases after cert but before decision
replace R_postKSRcert=0 if PostKSR==1
gen R_Obvious = 1 if R_CAFC_Result==1
replace R_Obvious=0 if R_CAFC_Result==2

tab R_ProceduralPosture, gen(pp)
rename (pp1 pp2 pp3 pp4 pp5 pp6) (R_jury R_bench R_jmol R_sj R_prelim R_multiple)

*gen HS_multiple = 0 if HS_Dataset==1
*replace HS_multiple = 1 if HS_ProceduralPosture==6

label var HS_postKSRcert "Post-KSR Cert"
label var R_postKSRcert "Post-KSR Cert"
label var HS_Obvious "Obvious"
label var R_Obvious "Obvious"
label var HS_bench "Bench"
label var HS_jury "Jury"
label var HS_jmol "JMOL"
label var HS_sj "SJ"
label var HS_prelim "Prelim. Injunction"
label var HS_other "Other"
label var R_bench "Bench"
label var R_jury "Jury"
label var R_jmol "JMOL"
label var R_sj "SJ"
label var R_prelim "Prelim. Injunction"
label var R_multiple "Multiple Postures"

**# Appendix C. PROBIT ESTIMATES OF THE LIKELIHOOD THE FEDERAL CIRCUIT FINDS OBVIOUSNESS POST-KSR GRANT OF CERT
dprobit HS_Obvious HS_postKSRcert
estimates store obvious1

dprobit R_Obvious R_postKSRcert
estimates store obvious2

dprobit HS_Obvious HS_postKSRcert HS_bench HS_jury HS_jmol HS_sj 
estimates store obvious3

dprobit R_Obvious R_postKSRcert R_bench R_jury R_jmol R_sj
estimates store obvious4

keep if Comparison_Set==1

dprobit HS_Obvious HS_postKSRcert
estimates store obvious5

dprobit R_Obvious R_postKSRcert
estimates store obvious6

dprobit HS_Obvious HS_postKSRcert HS_bench HS_jury HS_sj 
estimates store obvious7

dprobit R_Obvious R_postKSRcert R_bench R_jury R_sj
*There aren't any prelim or mlutiple obs. So have to lose one var to avoid perfect collinearity. 
estimates store obvious8

**# Appendix C1. PROBIT ESTIMATES OF THE LIKELIHOOD THE FEDERAL CIRCUIT FINDS OBVIOUSNESS POST-KSR GRANT OF CERT
estout obvious1 obvious2 obvious5 obvious6 using obvious1.txt, replace cells(b(star fmt(2)) se(nopar))  stats(N ll, labels("No. of Observations" "Log-likelihood")) starlevels(* 0.10 ** 0.05 *** 0.01) legend label collabels(none) margin 

**# Appendix C2. PROBIT ESTIMATES OF THE LIKELIHOOD THE FEDERAL CIRCUIT FINDS OBVIOUSNESS POST-KSR GRANT OF CERT
estout obvious3 obvious4 obvious7 obvious8 using obvious2.txt, replace cells(b(star fmt(2)) se(nopar)) stats(N ll, labels("No. of Observations" "Log-likelihood")) starlevels(* 0.10 ** 0.05 *** 0.01) legend label collabels(none) margin

 
log close












